<template lang="html">
<div id="login">
  <el-card class="box-card">
      <div slot="header" class="clearfix center_item">
        <span>后台管理系统登录</span>
      </div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" class="loginForm">
        <el-form-item label="登录名" prop="loginName">
            <el-input v-model="ruleForm.loginName"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="ruleForm.password"></el-input>
        </el-form-item>

    </el-form>
    <div class="center_item">
      <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </div>
    
    </el-card>
</div>

</template>
<script>

  import {router, dynamicRouter} from '@/router/index'
  import md5 from 'js-md5';
  export default {
    data() {
      return {
        ruleForm: {
          loginName: '',
          password: '',
          vueFile:''
        },
        rules: {
          loginName: [
            { required: true, message: '请输入登录名', trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ],
          
        }
      };
    },
    created() {
      
    },
    methods: {
      submitForm(formName) {
        var _this = this;

        _this.$refs[formName].validate((valid) => {
          if (valid) {
            var subObj = {loginName:_this.ruleForm.loginName, password:md5("ltsh:"+_this.ruleForm.password)};
            _this.myUtils.appRequest({
              method:'post',
              url: '/java/sys/user/login',
              data: subObj,
              callback:function(data) {
                if(data.content != null) {
                  localStorage.setItem(_this.globalConfig.sessionKey.ltsh_session_user_token, JSON.stringify(data.content.sysUser));
                  localStorage.setItem(_this.globalConfig.sessionKey.ltsh_session_menus, JSON.stringify(data.content.menus));
                  
                }
                
                _this.$router.push({path:'/main'});
              },catch: function(res) {
                 _this.$message({
                    showClose: true,
                    message: "服务器异常",
                    type: 'error'
                });
              }
            }, _this);
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      
    }
  }
</script>
<style>
#login .center_item{
  text-align: center;
}
#login .loginForm{
  padding:0 20px;
}
#login .el-card__body {
  padding:20px 0;
}
#login .box-card {
    margin:auto;
    width:100%;
    max-width: 450px;
    margin-top: 50px;
}
</style>

